﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MathLib {
    class MatrixA: Matrix {

        public double IsStable { get; private set; }

        public MatrixA(int n, Matrix f, Matrix m): base(n, n) {
            for (int j = 0; j < n; j++)
                this[0, j] = f[j, 0];
            for (int i = 1; i < n; i++)
                this[i, i - 1] = m[i - 1, 0];

            IsStable = CheckStability(f, m);
        }

        private static double CheckStability(Matrix f, Matrix m) {
            double c = 1;
            double r = 0;
            for (int i = 0; i < f.NoRows; i++) {
                c = 1;
                for (int j = 0; j <= i - 1; j++)
                    c *= Math.Round(m[j,0],2);
                r += Math.Round(f[i, 0] * c, 2);

            }
            return r;
        }
    }
}